package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.AiRecordingDuan;
import com.ruoyi.common.core.domain.entity.AiRecordingMain;
import com.ruoyi.common.core.domain.entity.RecordDuanVo;
import com.ruoyi.system.mapper.AiRecordingMainMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.AiRecordingChild;
import com.ruoyi.system.service.IAiRecordingChildService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AI录音子，记录每一条Controller
 *
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/system/child")
public class AiRecordingChildController extends BaseController
{
    @Autowired
    private IAiRecordingChildService aiRecordingChildService;
    @Autowired
    private AiRecordingMainMapper aiRecordingMainMapper;
    /**
     * 查询AI录音子，记录每一条列表
     */
//    @PreAuthorize("@ss.hasPermi('system:child:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiRecordingChild aiRecordingChild)
    {
        startPage();
        List<AiRecordingChild> list = aiRecordingChildService.selectAiRecordingChildList(aiRecordingChild);
        return getDataTable(list);
    }

    /**
     * 查询AI录音子，记录每一条列表
     */
//    @PreAuthorize("@ss.hasPermi('system:child:list')")
    @GetMapping("/listByMainId")
    public AjaxResult listByMainId(AiRecordingChild aiRecordingChild)
    {
        startPage();
        List<AiRecordingDuan> list = aiRecordingChildService.selectRecordDuanVo(aiRecordingChild);
        return AjaxResult.success(list);
    }


    @GetMapping("/listByMainIdToSpear")
    public AjaxResult listByMainIdToSpear(AiRecordingChild aiRecordingChild)
    {

        List<AiRecordingChild> list = aiRecordingChildService.listByMainIdToSpear(aiRecordingChild);
        return AjaxResult.success(list);
    }

    /**
     * 修改AI录音子，记录每一条
     */
//    @PreAuthorize("@ss.hasPermi('system:child:edit')")
    @Log(title = "AI录音子，记录每一条", businessType = BusinessType.UPDATE)
    @PutMapping("/updateDuan")
    public AjaxResult updateDuan(@RequestBody AiRecordingMain aiRecordingMain)
    {
        return aiRecordingChildService.updateAiRecordingChildDuan(aiRecordingMain);
    }

    /**
     * 导出AI录音子，记录每一条列表
     */
//    @PreAuthorize("@ss.hasPermi('system:child:export')")
    @Log(title = "AI录音子，记录每一条", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiRecordingChild aiRecordingChild)
    {
        List<AiRecordingChild> list = aiRecordingChildService.selectAiRecordingChildList(aiRecordingChild);
        ExcelUtil<AiRecordingChild> util = new ExcelUtil<AiRecordingChild>(AiRecordingChild.class);
        util.exportExcel(response, list, "AI录音子，记录每一条数据");
    }

    /**
     * 获取AI录音子，记录每一条详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:child:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiRecordingChildService.selectAiRecordingChildById(id));
    }

    /**
     * 新增AI录音子，记录每一条
     */
//    @PreAuthorize("@ss.hasPermi('system:child:add')")
    @Log(title = "AI录音子，记录每一条", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiRecordingChild aiRecordingChild)
    {
        return toAjax(aiRecordingChildService.insertAiRecordingChild(aiRecordingChild));
    }

    /**
     * 修改AI录音子，记录每一条
     */
//    @PreAuthorize("@ss.hasPermi('system:child:edit')")
    @Log(title = "AI录音子，记录每一条", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody AiRecordingChild aiRecordingChild)
    {
        return toAjax(aiRecordingChildService.updateAiRecordingChild(aiRecordingChild));
    }

    /**
     * 删除AI录音子，记录每一条
     */
//    @PreAuthorize("@ss.hasPermi('system:child:remove')")
    @Log(title = "AI录音子，记录每一条", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiRecordingChildService.deleteAiRecordingChildByIds(ids));
    }
}
